<%@page import="java.text.SimpleDateFormat" %>
<%@page import="java.util.Date" %>
<%@page import="com.xnx3.wangmarket.Authorization" %>
<%@page import="com.xnx3.j2ee.util.SafetyUtil" %>
<%@page import="com.xnx3.j2ee.Global" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
    //登陆用户名
    String username = SafetyUtil.filter(request.getParameter("username"));
    if (username == null || (username != null && username.equals("null"))) {
        username = "";
    }

    //登陆密码
    String password = SafetyUtil.filter(request.getParameter("password"));
    if (password == null || (password != null && password.equals("null"))) {
        password = "";
    }
%>
<jsp:include page="../common/head.jsp">
    <jsp:param name="title" value="登录"/>
</jsp:include>
<!-- Meta tag Keywords -->
<meta name="viewport" content="width=device-width, initial-scale=1">

<!-- <link href="${STATIC_RESOURCE_PATH}plugin/login/css/Noto-Sans_JP.css" rel="stylesheet"> -->
<link rel="stylesheet" href="${STATIC_RESOURCE_PATH}plugin/login/css/style.css" type="text/css" media="all"/>
<link rel="stylesheet" href="${STATIC_RESOURCE_PATH}plugin/login/css/font-awesome.min.css" type="text/css" media="all">

<style>
    .demo-login-container {
        width: 320px;
        margin: 21px auto 0;
    }

    .demo-login-other .layui-icon {
        position: relative;
        display: inline-block;
        margin: 0 2px;
        top: 2px;
        font-size: 26px;
    }
</style>



<form class="layui-form">
    <div class="demo-login-container">
        <h1><span><%=Global.get("SITE_NAME") %></span></h1>
        <div class="layui-form-item">
            <div class="layui-input-wrap">
                <div class="layui-input-prefix">
                    <i class="layui-icon layui-icon-username"></i>
                </div>
                <input type="text" name="username" value="<%=username %>" lay-verify="required" placeholder="请输入 用户名/邮箱" lay-reqtext="请填写用户名" autocomplete="off" class="layui-input" lay-affix="clear">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-wrap">
                <div class="layui-input-prefix">
                    <i class="layui-icon layui-icon-password"></i>
                </div>
                <input type="password" name="password" id="password" value="<%=password %>" lay-verify="required" placeholder="请输入密码" lay-reqtext="请填写密码" autocomplete="off" class="layui-input" lay-affix="eye">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-row">
                <div class="layui-col-xs7">
                    <div class="layui-input-wrap">
                        <div class="layui-input-prefix">
                            <i class="layui-icon layui-icon-vercode"></i>
                        </div>
                        <input type="text" name="code" value="" lay-verify="required" placeholder="请输入右边验证码" lay-reqtext="请填写验证码" autocomplete="off" class="layui-input" lay-affix="clear">
                    </div>
                </div>
                <div class="layui-col-xs5">
                    <div style="margin-left: 10px;">
                        <img id="code" src="captcha.do" onclick="reloadCode();" style="cursor: pointer;"/>
                    </div>
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <input type="checkbox" name="switch" lay-skin="primary" title="记住密码">
            <a href="#forget" style="float: right; margin-top: 7px;">忘记密码？</a>
        </div>

        <div class="layui-form-item">
            <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="formDemo">登录</button>
        </div>

        <div class="layui-form-item demo-login-other">
            <label>社交账号登录</label>
            <span style="padding: 0 21px 0 6px;">
        <a href="javascript:;"><i class="layui-icon layui-icon-login-qq" style="color: #3492ed;"></i></a>
        <a href="javascript:;"><i class="layui-icon layui-icon-login-wechat" style="color: #4daf29;"></i></a>
        <a href="javascript:;"><i class="layui-icon layui-icon-login-weibo" style="color: #cf1900;"></i></a>
      </span>
            或 <a href="#reg">注册帐号</a>
        </div>
    </div>

    </div>
</form>


<!-- js -->
<script src="/plugin/login/js/jquery.min.js"></script>
<!-- //js -->
<script>
    var STATIC_RESOURCE_PATH = '${STATIC_RESOURCE_PATH}';
    //STATIC_RESOURCE_PATH = '/';
</script>
<script src="/plugin/login/js/jquery.vide.js"></script>
<script>

    layui.use('form', function () {
        var form = layui.form;

        //监听提交
        form.on('submit(formDemo)', function (data) {
            msg.loading("登陆中");
            var d = $("form").serialize();
            $.post("wangmarketLoginSubmit.do", d, function (result) {
                msg.close();
                var obj = JSON.parse(result);
                try {
                    console.log(obj);
                } catch (e) {
                }
                if (obj.result == '1') {
                    localStorage.setItem('token', obj.token);
                    msg.success("登陆成功", function () {
                        window.location.href = obj.info;
                    });
                } else if (obj.result == '0') {
                    //登陆失败
                    msg.failure(obj.info);
                    reloadCode();
                } else if (obj.result == '11') {
                    //网站已过期。弹出提示
                    reloadCode();
                    layer.open({
                        title: '到期提示'
                        , content: obj.info
                    });
                } else {
                    reloadCode();
                    msg.failure(result);
                }
            }, "text");
            return false;
        });
    });

    //重新加载验证码
    function reloadCode() {
        var code = document.getElementById('code');
        code.setAttribute('src', 'captcha.do?' + Math.random());
    }

</script>

<jsp:include page="../common/foot.jsp"></jsp:include>